package com.banana.springcloud.controller;

import com.banana.springcloud.entity.CommonResult;
import com.banana.springcloud.entity.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author layman
 * @date 2021/1/21
 */
@RestController
public class AlibabaProviderController {

    @Value("${server.port}")
    private String serverPort;

    private static Map<Long,Payment> map = new HashMap<>();

    //模拟数据库操作
    static {
        map.put(1L, new Payment(1L, "28a8c1e3bc2742d8848569891fb42181"));
        map.put(2L, new Payment(2L, "28a4c1e3bc2742d8848569891fb42181"));
        map.put(3L, new Payment(3L, "28a5c1e3bc2742d8848569891fb42181"));
    }

    @GetMapping(value = "/payment/nacos/{id}")
    public CommonResult getPayment(@PathVariable("id") Integer id) {
        Payment payment = map.get(id);
        CommonResult<Payment> result = new CommonResult<>(200, "from mysql,serverPort: " + serverPort, payment);
        return result;
    }
}
